import pygame
from pygame.locals import *
import time

class heroPlane:
	#玩家飞机类
	def __init__(self,screen_temp):
		self.x=200
		self.y=400
		self.screen=screen_tempse
		self.image=pygame.image.load("./images/me.png")
	def display(self):
		self.screen.blit(self.image,(self.x,self.y))
	def move_left(self):
		self.x-=5
		if self.x<0:
			self.x=0
	def move_right(self):
		self.x+=5
		if self.x>406:
			self.x=406
class Bullet:
	def __init__(self,screen_temp,x,y):
		self.x=x
		self.y=y
		self.screem=screen_temp
		self.image=pygame.image.load("./pd.png")

	def display(self):
		self.screen.blit(self.image,(self.x,self.y))
	def move(self):
		self.y-=10
		if self.y<20:
			return True
def key_control():
	for event in pygame.event.get():
		#判断是否点击了退出按钮
		if event.type==QUIT:
			print("exit")
			exit()
	pressed_keys=pygame.key.get_pressed()	
	if pressed_keys[K_LEFT] or pressed_keys[K_a]:
		print('left')
		hero_temp.move_left()
	elif pressed_keys[K_RIGHT] or pressed_keys[K_d]:
		print('right')
		hero_temp.move_right()
	elif pressed_keys[K_SPACE]:
		print('space')
		hero_temp.fire()

def main():
	screen=pygame.display.set_mode((512,568),0,0)
	background=pygame.image.load(("./images/bg2.jpg"))
	m=-968
	while True:
		screen.blit(background,(0,m))
		m+=2
		if m>=-200:
			m=-968
		key_control()
		pygame.display.update()
		time.sleep(0.04)

if __name__=="__main__":
	main()

